package com.practice.designMode.coupon;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CouponStrategyFactory {

    private final Map<CouponType,CouponRuleStrategy> strategyMap = new HashMap<>();

    public CouponStrategyFactory(){
        strategyMap.put(CouponType.DISCOUNT,new DiscountStrategy());
        strategyMap.put(CouponType.FULL,new FullReductionStrategy());
    }

    // 这里要是用spring可以直接自动注入
    public CouponStrategyFactory(List<CouponRuleStrategy> strategies) {
        for (CouponRuleStrategy strategy : strategies) {
            strategyMap.put(strategy.supportCouponType(), strategy);
        }
    }

    public CouponRuleStrategy getStrategy(CouponType couponType){
        return strategyMap.get(couponType);
    }
}
